const mysql = require("mysql");

const pool = mysql.createPool(require("../../configs/mysqlConfiguration"));

const exec = (sql, params) => {
    return new Promise(function (resolve, reject) {
        pool.getConnection(function (err, conn) {
            if (err) {
                console.log("连接数据库失败!");
                reject(err)
            }

            conn.query(sql, params, function (err, results) {
                conn.release();
                if (err) {
                    console.log("执行sql语句失败!");
                    reject(err)
                }
                resolve(results);
            })
        })
    })
}

module.exports = { exec };